package org.sample.aaatest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 业务层
 */
@Service
public class TestService {
    @Autowired
    private TestSingle testSingle;

    public TestBean findTestById(int id) {
        System.out.println("TestService\tfindTestById: id=" + id);
        System.out.println("TestService\ttestSingle=" +testSingle.getClass().getName());
//        System.out.println("TestService\tTestSingle.getInstance()=" + TestSingle.getInstance().getClass().getName());
        return testSingle.getTestById(id);
    }

    public void addUser(TestBean user) {
        System.out.println("TestService\taddUser: user=" + user);
        System.out.println("TestService\taddUser: testSingle=" + testSingle.getClass().getName());
//        TestSingle.getInstance().addUser(user);
        testSingle.addUser(user);
    }

    public void deleteUser(int userId) {
        System.out.println("TestService\tdeleteUser: userId=" + userId);
        TestSingle.getInstance().deleteUser(userId);
    }

    public long count(){
        long count = TestSingle.getInstance().count();
        System.out.println("TestService\tcount: " + count);
        return count;
    }

    public List<TestBean> getAll(){
        List<TestBean> all = TestSingle.getInstance().getAll();
        System.out.println("TestService\tgetAll: all=" + all.size());
        return all;
    }


}
